package code.whmmm.util.hikari.jdbcpool;

import com.zaxxer.hikari.pool.HikariPool;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * <p><b>
 * 无事务的 数据库工具类
 * </b></p>
 * <br/>
 * 创建时间: 2019/10/12 8:49
 *
 * @author Zero
 */
public class SimpleDbUtil extends AbstractDbUtil {

    public SimpleDbUtil(HikariPool p) {
        super(p);
    }

    public SimpleDbUtil(JdbcPoolConfig config) {
        super(config);
    }

    @Override
    public Connection getConn() {
        try {
            return pool.getConnection();
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    @Override
    public void afterSql(ResultSet rs, Statement ps, Connection cn) {
        close(rs, ps, cn);
    }

    @Override
    public void exceptionCallback(Exception e) {

    }


    @Override
    public void commit(Connection cn) throws SQLException {
        cn.commit();
    }

    @Override
    public void rollback(Connection cn) throws SQLException {
        cn.rollback();
    }


}
